package com.example.demo.api.controller;

import com.example.demo.app.service.StudentService;
import com.example.demo.domain.entity.Student;
import com.example.demo.domain.entity.User;
import com.example.demo.domain.vo.StudentCourseGradesVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/student")
public class StudentController {
    @Autowired
    private StudentService studentService;
    @GetMapping("/{id}")
    public Student get(@PathVariable("id") Integer id){
        return studentService.queryStudentById(id);
    }

    @GetMapping("/list")
    public List<Student> get(){
        return studentService.queryStudentList();
    }

    @PostMapping
    public Integer add(@RequestBody Student student){
        return studentService.addStudent(student);
    }

    @PutMapping
    public Integer save(@RequestBody Student student){
        return studentService.saveStudent(student);
    }

    @PostMapping("/{id}")
    public Integer delete(@PathVariable("id") Integer id){
        return studentService.deleteStudentById(id);
    }

    @GetMapping("grades")
    public List<StudentCourseGradesVO> getGrades(String sname){
        return studentService.queryStudentCourseGrade(sname);
    }
}
